/**
 * 签到页面
 * author:yinht
 * date:2017年6月1日9:10:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");

	var pending_details = {
		listtype:"",
		/**
		 * bindEvent 页面事件
		 */
		bindEvent: function() {
			//返回
			$("#return_pendingdetails").unbind().on("click", function() {
				window.localStorage.setItem("type", "");
				window.localStorage.setItem("pk_member", "");
				window.history.back(-1);
			});
			//			$(".pro_po_list>li").unbind().on("click", function() {
			//				$(this).css("background-color","#4381e1");
			//			});
			//被驳回
			$("#bohui").unbind().on("click", function() {
				var picker = new mui.PopPicker();
				picker.setData([{
					value: '1',
					text: '金额与等级不匹配1'
				}, {
					value: '2',
					text: '金额与等级不匹配2'
				}, {
					value: '3',
					text: '金额与等级不匹配2'
				}, {
					value: '4',
					text: '其他原因'
				}]);

				picker.show(function(selectItems) {
					var valuetab = "1";
					var texttab = selectItems[0].text;
					console.log(valuetab);
					console.log(texttab);
					pending_details.sendReject(valuetab,texttab);
					picker.dispose();
				}, function(selectItems) {
					picker.dispose();
				});
			});
			//编辑
			$("#bianji").unbind().on("click", function() {
				window.sessionStorage.setItem("bianji","0");
				window.location.href = "#/index/newmenber";
			});
			//审核通过
			$("#pendingpass").unbind().on("click", function() {
				var valuetab = "0";
				var texttab = "通过";
				console.log(valuetab);
				console.log(texttab);
				pending_details.sendReject(valuetab,texttab);
			});
		},
		/**
		 * 进行页面路由监听配置
		 * 
		 */
		bindRout: function() {
			//			//公共页面监听路由
			//			Path.map("#home").to(function() {
			//				//返回首页
			//				common.loadPage({
			//					pageUrl: "html/index.html",
			//					reload: true,
			//					from: "left"
			//				});
			//			});
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				var from = "right"; //从右边过来
				if((page_name == "pending") || (page_name == "ManagementSup") || (page_name == "memberShip") || (page_name == "Management") || (page_name == "followalert") || (page_name == "birthdayremind")) {
					from = "left";
				} else {
					from = "right";
				}
				//记录状态
				common.loadPage({
					pageUrl: "html/" + page_name + ".html",
					reload: true,
					from: from
				});
			});
			Path.listen();
		},

		/**
		 * 页面数据加载
		 */
		loadData: function() {
			//接口数据
			var type = window.localStorage.getItem("type");
			var permissions = window.localStorage.getItem("permissions");
			if(permissions == "1") {
				$(".tobox").text("发起人：");
				if(type == "2") {
					$("#editor").css("display", "none");
					$(".sp_top_reject").css("display", "none");
				} else if(type == "3") {
					$("#editor").css("display", "none");
					$(".pro_footer").css("display", "none");
					$(".sp_top_reject").css("display", "none");
				}
				//加载数据

			}

			//初始化信息
			var initializestr = window.localStorage.getItem("initialize");
			var supertype = window.localStorage.getItem("supertype");
			var pk_user = window.localStorage.getItem("pk_user");
			var pk_member = window.localStorage.getItem("pk_member");
			var initializeObj = JSON.parse(initializestr);
			var docker = initializeObj.userInfo.psnName;
			var dockertel = initializeObj.userInfo.phone;
			$(".dockertel").text(dockertel);
			var listtype = window.localStorage.getItem("listtype");
			
			var param = {
				pk_user: pk_user,
				pk_member: pk_member,
				supertype: supertype, //判断是待审批还是被驳回还是会员
				listtype: listtype //判断是新增还是变更
			}
			common.loadData({
				url: "/service/RRTPubServlet?method=getdetail4approval", //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: pending_details.getMemberDetailCallBack, //回调函数
				dataSource: "getMemList",
				cache: false
			});
			var iscroll = require("iscroll");
			common.initIscroll({
				container: "iscrollContent_pending_details",
				isVertical: true,
				showScrollBar: true
			});
		},
		getMemberDetailCallBack: function(json) {
			console.log(JSON.stringify(json));
			if(json.status == "0") {
				pending_details.listtype = json.data.listtype;
				$(".pendingname").text(json.data.docker);
				$(".docker").text(json.data.docker);
				$(".khname").text(json.data.name);
				$(".sex").text(json.data.sex);
				$(".khbirth").text(json.data.birthday);
				$(".khtel").text(json.data.tel);
				$(".khaddress").text(json.data.address.receiverProvince + json.data.address.receiverCity + json.data.address.receiverRegion);
				$(".addressdetails").text(json.data.address.receiverAddr);
				$(".national").text(json.data.national);
				$(".Ancestral").text(json.data.Ancestral);
				$(".hobby").text(json.data.hobbies);
				$(".entityname").text(json.data.entityname);
				$(".subordinate").text(json.data.subordinate);
				$(".position").text(json.data.position);
				var label = json.data.memolabel;
				if(label && label.length>0){
					var html = "";
					for(var i=0;i<label.length;i++){
						html += '<span class="lablespan">'+label[i]+'</span>';
						}
					$(".label").append(html);
				}
				$(".consumption").text(json.data.consumption);
				$(".level").text(json.data.level);
				$(".Consumptionlevel").text(json.data.consumptionlevel);
				$(".mygoodsitems").text(json.data.myseries);
				$(".mygood").text(json.data.mygood);
				$(".competinggood").text(json.data.competinggood);
				$(".competinggooditems").text(json.data.competinggooditems);
				$(".pendingname").text(json.data.superior);
			} else {
				common.showTip({
					content: json.message
				});
			}
		},
		sendReject: function(valuetab,texttab){
			console.log(texttab);
			var pk_user = window.localStorage.getItem("pk_user");
			var pk_member = window.localStorage.getItem("pk_member");
			var param = {
				pk_user: pk_user,
				pk_member: pk_member,
				value:valuetab,
				message:texttab,
				listtype: pending_details.listtype //判断是新增还是变更
			}
			common.loadData({
				url: "/service/RRTPubServlet?method=reviewPass", //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: pending_details.pendDetailCallBack, //回调函数
				dataSource: "getMemList",
				cache: false
			});
		},
		pendDetailCallBack: function(json){
			console.log(JSON.stringify(json));
			if(json.status == "0") {
				window.history.back(-1);
			} else {
				common.showTip({
					content: json.message
				});
			}
		},
		/**
		 * each page init mothed
		 */
		initialize: function() {

			this.loadData();
			//事件绑定
			this.bindEvent();
			//路由绑定
			this.bindRout();
		}
	};

	module.exports = pending_details;
});